##__iter__方法和__next__方法
##class Fibs:
##    def __init__(self,n=10):
##          self.a = 0
##          self.b = 1
##          self.n = n
##    def __iter__(self):
##        return self
##    def __next__(self):
##        self.a, self.b = self.b, self.a + self.b
##        if self.a > self.n:
##            raise StopIteration
##        return self.a
##
##fibs = Fibs()
##for each in fibs:
##    print(each)
##---------------1----------------------
##用 while 语句实现与以下 for 语句相同的功能
##for each in range(5):
##    print(each)

##num = iter(range(5))
##while 1:
##    try:
##        each = next(num)
##    except StopIteration:
##        break
##    print(each)
##-----------------2--------------------
## 写一个迭代器，要求输出至今为止的所有闰年
##import datetime as dt
##class LeapYear:
##    def __init__(self):
##        self.now = dt.date.today().year
##    def isLeapYear(self, year):
##        if (year%4 == 0 and year%100 != 0) or (year%400 == 0):
##            return True
##        else:
##            return False
##    def __iter__(self):
##        return self
##    def __next__(self):
##        while not self.isLeapYear(self.now):
##            self.now -= 1
##
##        temp = self.now
##        self.now -= 1
##        return temp
##
##leapYears = LeapYear()
##for i in leapYears:
##    if i >=2000:
##            print(i)
##    else:
##        break
            
##-----------------3--------------------        
##要求自己写一个 MyRev 类，功能与 reversed() 相同
##内置函数 reversed(seq) 是返回一个迭代器，是序列 seq 的逆序显示       

class MyRev:
    def __init__(self, strs):
        self.strs = strs
        self.len = len(strs)

    def __iter__(self):
        return self

    def __next__(self):
        if self.len == 0:
            raise StopIteration
        self.len -= 1
        return self.strs[self.len]
        



























